<template>
	<!-- 发单工作台 -->
	<view class="send-out-page">
		<view class="btns">
			<view class="btn">
				<icon class="icon icon-team"></icon>
				<view>公司团队</view>
			</view>
			<view class="btn">
				<icon class="icon icon-project"></icon>
				<view>项目管理</view>
			</view>
			<view class="btn">
				<icon class="icon icon-area"></icon>
				<view>地址选择</view>
			</view>
			<view class="btn">
				<icon class="icon icon-invoice"></icon>
				<view>发票申请</view>
			</view>
		</view>
		<view class="order-form">
			<view class="order-form-t">
				订单管理
			</view>
			<view class="tab-btns">
				<view class="btn" v-for="(item,index) in items" :key="index" :class="current === index ? 'active' : ''"
					:style="{width: `calc(100% / ${items.length} )`}" @click="current = index">
					{{item}}
				</view>
			</view>
			<view class="nums">
				<view class="num">
					<view>18</view>
					<p class="label">全部</p>
				</view>
				<view class="num">
					<view>7</view>
					<p class="label">报名中</p>
				</view>
				<view class="num">
					<view>5</view>
					<p class="label">已中标</p>
				</view>
				<view class="num">
					<view>1</view>
					<p class="label">实施中</p>
				</view>
				<view class="num">
					<view>5</view>
					<p class="label">已完成</p>
				</view>
			</view>
		</view>
		<view class="order-list" :style="{height: 'calc('+ pageHeighthaveBar + 'px - 60px - 90px - 170px - 30px)'}">
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" @up="upCallback" :up="mescrolTop" :down="mescrolDown"
				:height="'calc('+ pageHeighthaveBar + 'px - 60px - 90px - 170px - 30px)'" @down="downCallback">
				<view class="order-list-item" v-for="(item, index) in resultListDate" :key="'order-list-item-'+index"
					@click="handleServiceDetails(item)">
					<view class="title">
						<text>{{ item.title }}</text>
						<text class="mony"> 
						{{
							Number(item.price) === 0 ?
							'面议' :
							`${Number(item.price).toFixed(2)} 元`
						}}
						</text>
					</view>
					<view class="tag">
						<view class="lt">
							<view class="time">
								{{handleTimeStrToTimeStamp(item.at)}}
							</view>
							<view class="impo" v-if="item.isShowTag">
								明天
							</view>
							<view class="area" v-if="item.serv_addr">
								{{ item.serv_addr }}
							</view>
						</view>
					</view>
					<view class="describe">
						<!-- <view class="tit">{{ item.stitle }}</view> -->
						<view class="details"> {{ item.content }} </view>
					</view>
					<view class="footer">
						<view class="end-time">
							<icon class="icon icon-time"></icon>
							{{
							handleTimeDifference(item.at, item.deadline) 
						}}
						</view>
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>


<script>
	import {
		getMyWorksheetCreated
	} from '@/utils/api.js';

	import {
		publics
	} from '@/mixins/publics.js';

	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [publics, MescrollMixin],
		data() {
			return {
				items: ['服务订单', '商城订单'],
				current: 0,
				mescrolTop: {
					use: true,
					page: {
						size: 10 // 每页数据的数量,默认10
					},
				},
				mescrolDown: {
					use: true,
					auto: false,
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					mustToTop: true
				},
				resultListDate: [],
				pageNum: 0,
				isNextPage: false
			};
		},
		created() {
			this.handleWindowArea()
		},
		methods: {
			// 详情
			handleServiceDetails(item) {
				uni.setStorageSync("workSheetDetails", item);
				uni.navigateTo({
					url: `/demandHallPages/service/serviceDetails?type=end`
				})
			},

			upCallback(page) {
				this.pageNum = page.num;
				this.pageSize = page.size;
				const postData = {
					pid: page.num, // 页码, 默认从1开始
					page_size: page.size,
				}
				this.getMyWorksheetCreatedApi(postData)
			},

			getMyWorksheetCreatedApi(postData) {
				getMyWorksheetCreated(postData).then(res => {
					if (res.code === 200) {
						this.resultListDate = res.data.worksheets;
						this.mescroll.endSuccess(this.resultListDate.length, this.isNextPage);
					} else {
						this.mescroll.endErr()
					}
				}).catch(data => {
					//  请求失败,隐藏加载状态
					this.mescroll.endErr()
				})
			},

			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}

				switch (e.currentIndex) {
					case 0:
						this.upCallback({
							num: 1,
							size: this.mescrolDown.page.size
						})
						break;
					case 1:

						break;
					default:
						break;
				}
			}
		}
	}
</script>

<style lang="scss">
	.send-out-page {
		background-color: #F2F3F7;

		.btns {
			padding: 22px 30px;
			width: 100%;
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			text-align: center;
			font-family: PingFangSC-Regular;
			font-weight: 400;
			font-size: 12px;
			color: #2C2C2C;
			box-sizing: border-box;

			.icon {
				width: 27px;
				height: 27px;
				margin: auto;

				&.icon-team {
					background: url("/static/images/icon/9.png");
					background-size: 100% 100%;
				}

				&.icon-project {
					background: url("/static/images/icon/10.png");
					background-size: 100% 100%;
				}

				&.icon-area {
					background: url("/static/images/icon/11.png");
					background-size: 100% 100%;
				}

				&.icon-invoice {
					background: url("/static/images/icon/12.png");
					background-size: 100% 100%;
				}
			}
		}

		.order-form {
			padding: 10px;
			margin-top: 10px;
			background-color: #fff;

			&-t {
				font-family: PingFangSC-SNaNpxibold;
				font-weight: 600;
				font-size: 15px;
				color: #1E1F23;
			}

			.tab-btns {
				width: 89.93vw;
				height: 38px;
				line-height: 34px;
				background: #F5F6FA;
				border-radius: 4px;
				background-color: #F5F6FA;
				color: #2C2C2C;
				display: flex;
				justify-content: space-around;
				align-items: center;
				text-align: center;
				padding: 4px;

				.btn.active {
					background-color: #fff;
				}
			}

			.nums {
				font-family: DINAlternate-Bold;
				font-weight: 700;
				font-size: 18px;
				color: #2C2C2C;
				display: flex;
				justify-content: space-between;
				text-align: center;
				width: 86.67vw;
				margin: auto;

				.label {
					font-family: PingFangSC-Regular;
					font-weight: 400;
					font-size: 12px;
					color: #2C2C2C;
				}
			}
		}

		.order-list {
			overflow: auto;
			margin-top: 10px;

			&-item {
				margin: 0 10px 10px;
				background-color: #fff;
				padding: 16px 12px 0px;
				border-radius: 10px;

				.title {
					display: flex;
					justify-content: space-between;
					font-family: PingFangSC-SNaNpxibold;
					font-weight: 600;
					font-size: 17px;
					color: #1E1F23;
					margin-bottom: 8px;

					.mony {
						font-size: 15px;
						color: #F54D3B;
					}
				}

				.tag {
					overflow: hidden;
					margin-bottom: 12px;

					.time,
					.impo,
					.area {
						display: inline-block;
						padding: 3px 7px;
						background: #F7F6FB;
						border-radius: 4px;
						color: #55525F;
						margin-right: 6px;
						font-size: 12px;

						&.impo {
							background-color: #22A366;
							color: #fff;
						}
					}

					.distance {
						font-family: PingFangSC-Regular;
						font-weight: 400;
						font-size: 12px;
						color: #55525F;
						letter-spacing: -0.7px;
						line-height: 23px;
					}
				}

				.describe {
					background: #F5F6FA;
					border-radius: 8px;
					padding: 8px 10px;
					font-size: 12px;
					margin-bottom: 12px;

					.tit {
						font-weight: 400;
						color: #181818;
						margin-bottom: 5px;
						font-size: 12px;
					}

					.details {
						color: #9B9B9B;
					}
				}

				.footer {
					height: 42px;
					line-height: 42px;
					border-top: 1px solid #f5f6fa;
					font-size: 12px;
					color: #9B9B9B;
					display: flex;
					justify-content: space-between;

					.icon {
						width: 12px;
						height: 12px;

						&.icon-time {
							background: url("/static/images/icon/time.png") no-repeat 0px 0px;
							background-size: 100% 100%;
						}

						&.icon-man {
							background: url("/static/images/icon/man.png") no-repeat 0px 0px;
							background-size: 100% 100%;
						}
					}
				}
			}
		}
	}
</style>